import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/components/Login";
import Home from "@/components/Home";
import Welcome from "@/components/Welcome";

import Hall from "@/components/admin/Hall";
import ManagerList from "@/components/admin/ManagerList";

import Permission from "@/components/admin/Permission";
import role from "@/components/admin/role";
import Comment from "@/components/admin/Comment"

import Movie from '@/components/admin/Movie.vue';
import Actor from '@/components/admin/actor.vue';
import Cinema from "@/components/admin/Cinema";
import schedule from "@/components/admin/schedule"
import User from "@/components/admin/User"
import Order from "@/components/admin/Order"
import confRoute from "@/components/admin/confRoute"

Vue.use(VueRouter)

const routes = [
    {
        path: "/",
        redirect: "/login"
    },
    {
        path: "/login",
        name: "Login",
        component: Login
    },


    {
        path: "/home",
        component: Home,
        redirect: "/welcome",
        children: [
            {
                path: "/welcome",
                component: Welcome
            },
            //安装右边admin字母顺序排的
            //演员
            {
                path: "/actor",
                component: Actor
            },
            //路由管理
            {
                path: "/confRoute",
                component: confRoute
            },
            //影院
            {
                path: "/cinema",
                component: Cinema
            },
            //评论
            {
                path: "/comment",
                component: Comment
            },
            {
                path: "/user",
                component: User
            },//门户用户

            //影厅
            {
                path: "/hall",
                component: Hall
            },
            //管理员
            {
                path: "/managerList",
                name: "ManagerList",
                component: ManagerList
            },
            {
                path: "/order",
                name: "Order",
                component: Order
            },
            //电影
            {
                path: "/movie",
                component: Movie

            },
            //权限
            {
                path: "/permission",
                component: Permission
            },
            //角色
            {
                path: "/role",
                component: role
            },
            //排片
            {
                path: "/schedule",
                name: "schedule",
                component: schedule
            },



            {
            path: "/cinema",
            component: Cinema
        },
        {
            path:"/schedule",
            name:"schedule",
            component:schedule
        }

        ]

    }

]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path == '/login') {
        return next();
    }

    const userCode = sessionStorage.getItem("userCode");
    if (!userCode) {
        return next("/login");
    } else {
        next();
    }
})

export default router
